Skip to content

fix: OSC 52 clipboard with execCommand fallback for user gesture requ… - #1565

Open
mdj2812 wants to merge 1 commit into
tsl0922:mainfrom
mdj2812:fix/osc52-clipboard-user-gesture
Open

fix: OSC 52 clipboard with execCommand fallback for user gesture requ…#1565
mdj2812 wants to merge 1 commit into
tsl0922:mainfrom
mdj2812:fix/osc52-clipboard-user-gesture

Conversation

@mdj2812

@mdj2812 mdj2812 commented Aug 7, 2026

Copy link
Copy Markdown

Problem

@xterm/addon-clipboard uses navigator.clipboard.writeText() which requires transient user activation. OSC 52 clipboard sequences arrive asynchronously from the PTY server via WebSocket — outside the browser's gesture window. The browser silently rejects the write, so Neovim/tmux/any OSC 52 clipboard integration does not work.

Fix

Register an additional OSC 52 handler after the ClipboardAddon that uses document.execCommand('copy') with a hidden <textarea>. The older execCommand API does not require user activation, making it a reliable fallback for asynchronous clipboard writes.

Testing

  1. Connect to ttyd, run:
    printf "\e]52;c;%s\a" "$(echo "hello" | base64)"
  2. Ctrl+V outside the browser → hello appears.

Tested on Fedora 43, Chromium browser.

…irement

navigator.clipboard.writeText() requires transient user activation,
but OSC 52 clipboard sequences arrive asynchronously from the PTY
server via WebSocket — outside the browser's gesture window.

Register an additional OSC 52 handler after the ClipboardAddon that
uses document.execCommand('copy') with a hidden textarea, which does
not require user activation.

Fixes clipboard integration for Neovim, tmux, and other terminal
programs that rely on OSC 52 sequences.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant